<script>
import { versionUpdate } from './utils/update';
//需要挂载到全局的变量
let globalData = {
  PRIMARY_COLOR: '#0165FC',
  PRIMARY_TEXT_COLOR: '#1C1F23',
  TABBAR_HEIGHT: 98
}
export default {
  globalData,
  onLaunch: async function () {
    versionUpdate(); // 校验版本更新
    //获取系统信息
    this.globalData.systemInfo = uni.getSystemInfoSync() ||  null;
    //获取存储的用户信息 并存在状态管理里面
    const storagePrivacy = this.$Serv.getPrivacyData('privacyData');
    if (Object.keys(storagePrivacy).length > 0) {
      // 页面启动时连接 
      await this.$store.commit('setStore', {
        privacyData: {...storagePrivacy}
      })
    }
    this.globalData.storageInfo = uni.getStorageInfoSync() || {}

  },
  onShow: async function (options) {
    console.log('app.vue===>', options);
    await this.$Serv.login();  //微信渠道授权登录
    const { openId, userId, token, roles } = this.$store.state.privacyData;
    if (openId && userId && token)  {
      this.callBack();
    }
    // 有boss 或hr身份才查企业列表
    if (roles.includes('boss') || roles.includes('hr')) {
      await this.$Serv.getEnterpriseList('init');  //获取企业列表
    }
    
    // await this.$Serv.getCommissionRateByAgentId();  // 获取各种规则详情
  },
  methods: {
    callBack() {
      // #ifndef H5
      console.log('执行ifndef H5');
      this.$scope.globalData.callBack && this.$scope.globalData.callBack();
      // #endif
    },
  },
  onHide: function () {
    this.globalData.callBack = null;
    console.log('App Hide')
  },
  created(){
    // this.$Serv.getLocation('onLaunch');  // 获取地址信息onLaunch=小程序启动 定位
  }
}
</script>
<style src="./static/styles.scss"></style>
<style src="./static/layout.scss"></style>
